package com.wisdytech.linkdcs.equipLifeCycle.maintain.action;


import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.DataTransformUtil;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.model.MTypeItem;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.model.MaintenanceItem;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.service.IMTypeItemService;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.vo.MaintenanceItemVO;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.vo.MaintenanceTypeItemVO;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenbin
 * @since 2018-06-10
 */
@Controller
@RequestMapping("/maintain/mTypeItem")
public class MTypeItemController {
	
	@Autowired
	private IMTypeItemService iMTypeItemService;
	
  /**
  * <p>Description: 保存关联保养项对象</p> 
  * @return 处理结果对象
  */
 @RequestMapping(value = "/saveTypeAndItem/save.mvc")
 @ResponseBody
 public StandardResult saveTypeAndItem(@ModelAttribute("typeId")String typeId, @ModelAttribute("itemIds")String itemIds) {
	 iMTypeItemService.addTypeAndItem(typeId, itemIds);
     return StandardResult.getSuccessResult();
 }
 
 
 /**
  * 分页条件查询保养项信息-关联保养项
  * @param itemCode 备件编码
  * @param itemName 备件名称
  * @param filter 分页参数
  * @return 保养项列表信息
  * @throws IOException 
  */
 @RequestMapping(value = "/listTypeItemByFilter/get.mvc")
 @ResponseBody	
 public StandardTableResult<MaintenanceTypeItemVO> listTypeItemByFilter(String pkId,Filter filter) throws IOException{
 	PageInfo<MaintenanceItem> items =this.iMTypeItemService.listTypeItemByFilter(pkId,filter);
 	List<MTypeItem> typeItems = this.iMTypeItemService.listTypeItemByPkId(pkId);
 	//转换为前台结果集
     List<MaintenanceItem> itemList=items.getList();
     List<MaintenanceTypeItemVO> itemVOList=new ArrayList<MaintenanceTypeItemVO>();
     for(MaintenanceItem maintenanceItem:itemList){
    	 itemVOList.add(DataTransformUtil.changeTypeItemVO(maintenanceItem,typeItems));
     }
     return new StandardTableResult<MaintenanceTypeItemVO>(items.getTotal(),itemVOList);
 }
 
 /**
  * @return 保养项列表信息
  * @throws IOException 
  */
 @RequestMapping(value = "/listTypeItemByTaskId/get.mvc")
 @ResponseBody	
 public StandardTableResult<MaintenanceItem> listTypeItemByTaskId(String taskId,Filter filter) throws IOException{
 	PageInfo<MaintenanceItem> items =this.iMTypeItemService.listTypeItemByTaskId(taskId,filter);
    return new StandardTableResult<MaintenanceItem>(items.getTotal(),items.getList());
 }
 
 
 
}

